//var searchLabel = Ti.UI.createLabel( {
//	color : '#FFFFFF',
//	text : 'Search by Region',
//	shadowColor : '#330000',
//	shadowOffset : {
//		x : 5,
//		y : 5
//	},
//	font: {fontSize: 14, fontWeight: 'bold'},
//	top : 10,
//	left : 10,
//	width : 'auto',
//	height : 'auto'
//});
//searchPanel.add(searchLabel);

var viewRegionContainer = Ti.UI.createView( {
//	backgroundColor : viewport_bg,
//	opacity : 0.30,
//	borderRadius : 10,
//	borderColor : viewport_border,
//	borderWidth : 1,
	backgroundImage: 'images/searchregion.png',
	width : 283,
	height : 172,
	top : 10,
	left : 19,
	layout: 'vertical'
});


var countryLabel = Ti.UI.createLabel( {
	color : '#FFFFFF',
	text : 'Country',
	top : 5,
	left : 10,
	width : 'auto',
	height : 'auto'
});
//viewRegionContainer.add(countryLabel);


var customData = [ 
	{label : "United States", hasChild : false, selected : true}, 
	{label : "Canada", hasChild : false}, 
	{label : "Germany",hasChild : false}, 
	{label : "Netherlands",hasChild : false} 
];

var selectedCountry = DotNetNuke.getSelectedDataRow(customData);

var picker = DotNetNuke.createPicker( {
	top : 5,
	left : 10,
	right : 10,
	height : 34,
	editable : true,
	hintText : selectedCountry.label,
	borderColor : '#700',
	borderWidth : 1
});

var selector;

picker.addEventListener('click', function(e) {
	var popup = Ti.UI.createWindow( {
		//modal : true,
		navBarHidden: true,
		backgroundColor : '#000',
		opacity : 0.10
	});

	selector = DotNetNuke.createSelector( {
		width : 290,
		height : 300,
		data : customData
	});

	selector.addEventListener('click', function(e) {
		popup.close();
		picker.fireEvent('setText', {
			text : customData[e.index].label
		});
		DotNetNuke.selectDataRow(customData, e.index);
	});

	popup.add(selector);
	popup.open();
});
//viewRegionContainer.add(picker);

var stateLabel = Ti.UI.createLabel( {
	color : '#FFFFFF',
	text : 'State/Region',
	top : 10,
	left : 10,
	width : 'auto',
	height : 'auto'
});
//viewRegionContainer.add(stateLabel);

var customStateData = [ 
  	{label : "Not Specified", hasChild : false, selected : true} 
];

var selectedState = DotNetNuke.getSelectedDataRow(customStateData);

var statePicker = DotNetNuke.createPicker( {
	top : 5,
	left : 10,
	right : 10,
	height : 34,
	editable : true,
	hintText : selectedState.label,
	borderColor : '#700',
	borderWidth : 1
});

var stateSelector;

statePicker.addEventListener('click', function(e) {
	var popup = Ti.UI.createWindow( {
		//modal : true,
		navBarHidden: true,
		backgroundColor : '#000',
		opacity : 0.10
	});

	stateSelector = DotNetNuke.createSelector( {
		width : 290,
		height : 300,
		data : customStateData
	});

	stateSelector.addEventListener('click', function(e) {
		popup.close();
		statePicker.fireEvent('setText', {
			text : customStateData[e.index].label
		});
		DotNetNuke.selectDataRow(customStateData, e.index);
	});

	popup.add(stateSelector);
	popup.open();
});
//viewRegionContainer.add(statePicker);

var searchRegion = Ti.UI.createButton({
	title:'Search by Region',
	top:10,
	right:10,
	height:35,
	width: 150
});
//viewRegionContainer.add(searchRegion);

searchRegion.addEventListener('click',function(e)
		{

			var xhr = Ti.Network.createHTTPClient();
			
			xhr.onload = function()
			{
		        var results = JSON.parse(this.responseText);
			};
			
			xhr.onerror = function(e){
				Ti.API.info('HttpClient Error:' + e.error);
			};
			
			xhr.open('POST', SearchByRegionUrl );
			xhr.setTimeout(10);
			xhr.setRequestHeader("Content-Type","application/json; charset=utf-8");
			var data = "{ 'country': '" + country + "' }";
			xhr.send(data);   
		        
		});

searchPanel.add(viewRegionContainer);
